package org.jeecg.modules.system.mapper;

import java.util.List;

import com.baomidou.mybatisplus.annotation.SqlParser;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.jeecg.modules.system.entity.SysDepart;
import org.jeecg.modules.system.entity.SysPermission;
import org.jeecg.modules.system.entity.SysUserRole;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.jeecg.modules.system.vo.SysUserRoleScope;
import org.springframework.stereotype.Repository;

/**
 * <p>
 * 用户角色表 Mapper 接口
 * </p>
 *
 * @Author scott
 * @since 2018-12-21
 */
@Repository
public interface SysUserRoleMapper extends BaseMapper<SysUserRole> {

	@Select("select role_code from sys_role where id in (select role_id from sys_user_role where user_id = (select id from sys_user where username=#{username}))")
	List<String> getRoleByUserName(@Param("username") String username);

	@Select("select role_type from sys_role where id in (select role_id from sys_user_role where user_id = (select id from sys_user where id=#{userId}))")
	List<String> getRoleByUserId(@Param("userId") String userId);

	public boolean deleteByMainId(String mainId);

	List<SysUserRole> selectByMainId(String mainId);

	@SqlParser(filter = true)
	List<SysUserRole> selectServerByMainId(@Param("id") String mainId,@Param("tenantId") String tenantId);

    void insertBatch(@Param("list") List<SysUserRole> list);

	void insertBatchHis(@Param("hisList") List<SysUserRole> delUserRoleList);

    List<SysDepart> queryDepartTreeList(@Param("menuPath") String menuPath,@Param("userId") String userId,
										@Param("departType") String departType,@Param("departIdEx") String departIdEx);
    List<SysDepart> queryDepartTreeListByKeywords(@Param("keyword") String keyword, @Param("menuPath") String menuPath,@Param("userId") String userId,
										@Param("departType") String departType,@Param("departIdEx") String departIdEx);

	List<SysDepart> queryProjectList(@Param("menuPath") String menuPath, @Param("userId") String userId,
									 @Param("departType") String departType,@Param("departIdEx") String departIdEx);

	List<SysDepart> queryProjectTreeListByDepartId(@Param("departIdList") List<String> departIdList);

    List<SysPermission> queryUserPermission(@Param("userId") String userId,@Param("tenantId") String tenantId,@Param("client") String client);


	//------------------------------------S端-START--------------------------------------------------
	@SqlParser(filter = true)
	List<SysUserRole> queryServerByUserId(@Param("tenantId") String tenantId,@Param("userId") String userId);
	@SqlParser(filter = true)
	void delServerUserRoleScope(@Param("bean") SysUserRoleScope sysUserRoleScope);
	@SqlParser(filter = true)
	void insertServerBatch(@Param("list") List<SysUserRole> addUserRoleList);
	@SqlParser(filter = true)
    void serverSave(@Param("bean") SysUserRole sysUserRole);

    //------------------------------------S端-END----------------------------------------------------
}
